﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Vorkos.Math
{
    class Program
    {
        public static void Main()
        {
            Console.Write(Literals.ENTERUINT64);
            uint n = EnterUint();
            SelectMode(n);
            Console.ReadKey();
        }
        public static void SelectMode(uint n)
        {
            Console.WriteLine(Literals.ENTERMODE);
            uint i=0; 
            i=EnterUint(3);
            switch (i)
            {
                case 1:
                    Factorial(n);
                    break;
                case 2:
                    SqrSum(n);
                    break;
                case 3:
                    PowSum(n);
                    break;
                default:
                    Factorial(n);
                    break;
            }
        }
        public static uint EnterUint()
        {
            uint result = 0;
            bool correctFlag = false;
            int maxValue = 6000;
            do
            {
                while (!uint.TryParse(Console.ReadLine(), out result)) 
                    Console.WriteLine(Literals.TRYAGAIN);
                if (result > maxValue) 
                {
                    Console.WriteLine(Literals.TRYAGAIN);
                    correctFlag = false;
                }
                else if (result < 1)
                {
                    Console.WriteLine(Literals.TRYAGAIN);
                    correctFlag = false;
                }
                else correctFlag = true;
            } while (!correctFlag);
            return result;
        }
        public static uint EnterUint(long maxValue)
        {
            uint result = 0;
            bool correctFlag = false;
            do
            {
                while (!uint.TryParse(Console.ReadLine(), out result))
                    Console.WriteLine(Literals.TRYAGAIN);
                if (result > maxValue)
                {
                    Console.WriteLine(Literals.TRYAGAIN);
                    correctFlag = false;
                }
                else if (result<1)
                {
                    Console.WriteLine(Literals.TRYAGAIN);
                    correctFlag = false;
                }
                else correctFlag = true;
            } while (!correctFlag);
            return result;
        }
        public static uint EnterUint(long maxValue, long minValue)
        {
            uint result = 0;
            bool correctFlag = false;
            do
            {
                while (!uint.TryParse(Console.ReadLine(), out result))
                    Console.WriteLine(Literals.TRYAGAIN);
                if (result > maxValue)
                {
                    Console.WriteLine(Literals.TRYAGAIN);
                    correctFlag = false;
                }
                else if (result < minValue)
                {
                    Console.WriteLine(Literals.TRYAGAIN);
                    correctFlag = false;
                }
                else correctFlag = true;
            } while (!correctFlag);
            return result;
        }
        public static void Factorial(uint n)
        {
            uint j = 0;
            ulong transit = 0;
            ulong[] resArray = new ulong[262144];
            resArray[0]=1;
            
            for (uint i = 1; i <= n; i++)
            {
                for (int k=0;k<=j;k++ )
                {
                    resArray[k] = i * resArray[k] + transit;
                    transit = (resArray[k] / 1000000L);
                    if (transit > 0 && resArray[j]>100000L) j++;
                    resArray[k] = resArray[k] % 1000000L;
                }
            }
            for (uint i = j+1; 0 < i; i--)
            {
                    Console.Write("{0:d6} ",resArray[i-1]);
            }

        }
        public static void SqrSum(uint n)
        {
            ulong[] resArray = new ulong[262];
            resArray[0]=0;
            Console.WriteLine();

            for (uint i = 1; i <= n; i++)
            {
                resArray[0] = i * i + resArray[0];
            }
            resArray[1] = (n*(n+1UL)*(2*n+1UL))/6;

            Console.Write("{0} = {1}", resArray[0], resArray[1]);
            
        }
        public static void PowSum(uint n)
        {
            uint j = 0;
            ulong transit = 0;
            ulong[] resArray = new ulong[262144];
            resArray[0] = 1;
            Console.WriteLine();
            for (uint i = 1; i <= n+1; i++)
            {
                for (int k = 0; k <= j; k++)
                {
                    resArray[k] = resArray[k]<<1;
                    resArray[k] = resArray[k] + transit;
                    transit = (resArray[k] / 1000000L);
                    if (transit > 0) j++;
                    resArray[k] = resArray[k] % 1000000L;
                }
                while (resArray[j] == 0)
                {
                    j--;
                }
            }
            resArray[0] = resArray[0] - 1;
            for (uint i = j + 1; 0 < i; i--)
            {
                //if (resArray[i - 1]>0)
                Console.Write("{0:d6} ", resArray[i - 1]);
            }

        }
    }
}
